package cn.tedu.demo.controller;

import cn.tedu.demo.entity.Admin;
import cn.tedu.demo.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired(required = false)
    AdminMapper mapper;

    @RequestMapping("/login")
    public int login(@RequestBody Admin admin){
        System.out.println("1111"+admin.toString());
        Admin a=(Admin) mapper.selectByName(admin.getName());
        if (a==null){
            //该用户不存在返回0
            return 0;
        }else {
            System.out.println(a.toString());
            if (admin.getPassword().equals(a.getPassword())){
                //密码正确返回1
                return 1;
            }
            //密码错误返回2
            return 2;
        }
    }
}
